/**
 * Entity to store all sleep information.
 * start, end, where.
 * 
 * 
 * @author panthro.rafael@gmail.com
 * 
 */
package com.sleepsocial.persistency.entity.sleep;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.sleepsocial.persistency.entity.location.Location;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Sleep {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key      key;

    @Persistent
    private long     start;

    @Persistent
    private long     end;

    @Persistent
    private Location location;

    /**
     * Creates a new Sleep object with the stard and end information, location
     * can be null
     * 
     * @param start
     * @param end
     * @param location
     *            an {@link Location} instance
     */
    public Sleep(long start, long end, Location location) {
        super();
        this.start = start;
        this.end = end;
        this.location = location;
    }

    public Sleep(long start, long end) {
        super();
        this.start = start;
        this.end = end;
        this.location = null;
    }

    public void end() {
        end = System.currentTimeMillis();
    }

    public long getEnd() {
        return end;
    }

    public Location getLocation() {
        return location;
    }

    public long getStart() {
        return start;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public void start() {
        start = System.currentTimeMillis();
    }

    /**
     * @return the key
     */
    public Key getKey() {
        return key;
    }

}
